local feibai = fk.CreateSkill{
  name = "pegasus__feibai",
  tags = { Skill.Compulsory }
}

Fk:loadTranslationTable{
  ["pegasus__feibai"] = "飞白",
  [":pegasus__feibai"] = "锁定技，你使用指定其他角色为目标的牌时，弃置X张牌并分配一点伤害；然后你失去至少一个技能直到回合结束并摸等量的牌。",

  ["#pegasus__feibai-damage"] = "飞白：请弃置%arg张牌，分配1点伤害",
  ["pegasus__feibai-chuanwu"] = "飞白：请失去至少一个技能直到回合结束，摸等量的牌",
}

---@param player Player
---@return string[]
local getPlayerSkills = function (player)
  local skills = {}
  for _, s in ipairs(player.player_skills) do
    if s:isPlayerSkill(player) then
      table.insertIfNeed(skills, s.name)
    end
  end
  return skills
end

feibai:addEffect(fk.CardUsing, {
  anim_type = "offensive",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(feibai.name) and player == target and table.find(player.room.alive_players, function (p)
      return p ~= player and data:hasTarget(p)
    end)
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local num = math.min(player:getHandcardNum(), #getPlayerSkills(player))
    local tos, cards = room:askToChooseCardsAndPlayers(player, {
      min_card_num = num,
      max_card_num = num,
      targets = room.alive_players,
      max_num = 1,
      min_num = 1,
      skill_name = feibai.name,
      cancelable = false,
      will_throw = true,
      prompt = "#pegasus__feibai-damage:::" .. num,
    })

    room:throwCard(cards, feibai.name, player, player)

    if player:isAlive() then
      room:damage{
        to = tos[1],
        from = player,
        damage = 1,
        skillName = feibai.name,
      }
    end

    if player:isAlive() then
      local op = room:askToChoices(player, {
        choices = getPlayerSkills(player),
        min_num = 1,
        max_num = 999,
        detailed = true,
        skill_name = feibai.name,
      })

      table.forEach(op, function (skill)
        room:addTableMarkIfNeed(player, "pegasus__feibai", skill)
      end)
      room:handleAddLoseSkills(player, table.concat(table.map(op, function (e) return "-" .. e end), "|"))

      if player:isAlive() then
        player:drawCards(#op, feibai.name)
      end
    end
  end
})

feibai:addEffect(fk.TurnEnd, {
  can_refresh = function (self, event, target, player, data)
    return #player:getTableMark("pegasus__feibai") > 0
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    local skills = player:getTableMark("pegasus__feibai")
    room:setPlayerMark(player, "pegasus__feibai", 0)
    room:handleAddLoseSkills(player, table.concat(skills, "|"))
  end
})

return feibai